﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using 书易.Model;

namespace 书易.DAL
{
    /// <summary>
    /// 数据访问订单管理类
    /// </summary>
    public class OrdersDal
    {
        public static int add(Orders o) {
            return DbHelper.ExecuteNonQuery("insert into Orders values(@OID,@MID,@ODate,@OConsignee,@OAddress,@OTelephone,@OSumPrice,4)",new SqlParameter[]{
                new SqlParameter("@OID",o.OID),
                new SqlParameter("@MID",o.MID),
                new SqlParameter("@ODate",o.ODate),
                new SqlParameter("@OConsignee",o.OConsignee),
                new SqlParameter("@OAddress",o.OAddress),
                new SqlParameter("@OTelephone",o.OTelephone),
                new SqlParameter("@OSumPrice",o.OSumPrice),
            });
        }
        public static string addDDH() {
            string ymd = "DD"+DateTime.Now.ToString("yyyyMMdd");
            int no =1+Convert.ToInt32(DbHelper.ExecuteScalar("select ISNULL(CONVERT(int,RIGHT(MAX(OID),4)),0) from Orders where OID like '" + ymd + "%'")) ;
            return ymd + Convert.ToString(no).PadLeft(4, '0');
        }
    }
}
